﻿//-----------------------------------------------------------------------
// <copyright file="ConsoleLogProvider.cs" company="Anthony Steele">
// This source forms part of the DuplicateFinder utility
// Hosted at http://www.codeplex.com/DuplicateFinder
//
// logging code by John Miller
// This source is available under the terms of the Microsoft Public License (Ms-PL)
// See http://duplicatefinder.codeplex.com/license
// All other rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace DupFinder.Logging
{
    using System;

    using DuplicateFinderLib;

    /// <summary>
    /// Log Provider that writes to the console
    /// </summary>
    public class ConsoleLogProvider : ILogProvider
    {
        /// <summary>
        /// Logs messages to the console
        /// </summary>
        /// <param name="message">message to be logged</param>
        public void LogMessage(string message)
        {
            Console.WriteLine(message);
        }

        /// <summary>
        /// This logs information about the duplication
        /// </summary>
        /// <param name="e">Duplication information</param>
        public void LogDuplication(DuplicateEventArgs e)
        {
            Console.WriteLine("Duplicate of length {0} at: ", e.Length);
            foreach (LineItem dupItem in e.Items)
            {
                int endLine = dupItem.LineNumber + e.Length - 1;

                Console.WriteLine(" Line {0}-{1} in {2}", dupItem.LineNumber, endLine, dupItem.FileName);
            }
        }

        /// <summary>
        /// This logs the number of files that were processed
        /// </summary>
        /// <param name="fileCount">the number of files read</param>
        public void LogFileCount(int fileCount)
        {
            if (fileCount.Equals(1))
            {
                Console.WriteLine("1 file read");
            }
            else
            {
                Console.WriteLine("{0} files read", fileCount);
            }
        }

        /// <summary>
        /// This logs the number of duplicate items that were found
        /// </summary>
        /// <param name="duplicateCount">the number of duplicates found</param>
        public void LogDuplicateCount(int duplicateCount)
        {
            if (duplicateCount.Equals(1))
            {
                Console.WriteLine("1 duplicate found");
            }
            else
            {
                Console.WriteLine("{0} duplicates found", duplicateCount);
            }
        }

        /// <summary>
        /// This method is not used by the console log.
        /// </summary>
        public void Close()
        {
        }
    }
}
